﻿<!-- Modal -->
<div class="modal fade" id="myModal_AddCostClass" tabindex="-1" role="dialog" aria-labelledby="myModalAddCostClass" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h5 class="modal-title"><span class="glyphicon glyphicon-plus text-success"></span>&nbsp;增加费用名称</h5>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <form action="#" role="form">
                        <div class="form-group">
                            <label for="AddCostClassName">增加费用名称:</label>
                            <input type="text" name="AddCostClassName" class="form-control" placeholder="增加费用名称">
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <span class="text-success"></span>
                <button type="button" class="btn btn-default " data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="Btn_AddCostClass()">确认</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    $(function () {
        $('#myModal_AddCostClass form').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                AddCostClassName: {
                    message: '用户名验证失败',
                    validators: {
                        notEmpty: {
                            message: '商品名不能为空！'
                        }
                    }
                }


            }
        });
    });
</script>

<script type="text/javascript">
    var flag = false;//如果是提交就刷新
    $('#myModal_AddCostClass').on('hidden.bs.modal', function (e) {
        if (flag) {
            flag = false;
            //刷新下拉菜单绑定的商品分类
            $("#Pannel_ManageList").load("Admin/M_CostClass");
        }
    })
    function Btn_AddCostClass() {

        var bootstrapValidator = $('#myModal_AddCostClass form').data('bootstrapValidator');
        bootstrapValidator.validate();
        if (bootstrapValidator.isValid()) {
            $.ajax({
                type: 'POST',
                data: "CostClassName=" + $("#myModal_AddCostClass").find("input[name='AddCostClassName']").val(),

                url: 'Admin/Btn_AddCostClass',
                success: function (data) {

                    if (data == "ok") {
                        //$("#myModal_AddGords").modal("hide");
                        //刷新下拉菜单绑定的商品分类

                        //增加添加成功信息
                        flag = true;
                        $("#myModal_AddCostClass .modal-footer").find("span").show().html("添加成功！");
                        $('#myModal_AddCostClass').modal('toggle')



                    }
                    else { alert("没有成功"); }

                },
                error: function (error) {
                    alert(error.responseText);
                }
            });
        }
    }
</script>